
/**
 * Created by wxnacy on 2015/8/12.
 */
$(function() {

    submitForm();
    //上传图片组件
    initUploadImage();
    //艺人组件
    initStarr();
    //时间组件
    initClock();
    //edit数据初始化
    initEdit()

});

/**
 * 更改专辑后，video可以选择的艺人
 * @param $album
 * @param videoStarrId
 */
function initVideoStarr($album,videoStarrId,starrIds){
    var albumId = $album.val();
    if(albumId == ''){
        return;
    }
    var url = '/vrs/album/one.jsn?albumId='+albumId;
    $.get(url,function(data,status){
        if(status == 'success'){
            var _status = data.success;
            if(_status){
                var starringInfo = data.data.starringInfo;
                var starrJson = $.evalJSON(starringInfo);
                var starrList = starrJson.data;
                //console.log(starrJson);
                var optionList = new Array();
                optionList[0]='<option value=""></option>';
                $.each(starrList,function(i,item){
                    optionList[parseInt(i+1)]='<option value="'+item.starringId+'">'+item.name+'</option>';
                });
                var $newSelect = $('<select id="'+videoStarrId+'" required data-placeholder="请选择艺人"  multiple class="chosen" name="video.starringIds" style="width: 60%;">'+optionList.join()+'</select>');
                var $select =  $('#'+videoStarrId);
                //var $newSelect = $($select.clone(true).prop("outerHTML")).html(optionList.join(""));

                $select.next().remove();
                $select.replaceWith($newSelect);
                //$select.after($newSelect);
                $('.chosen').chosen();
                if(starrIds != ''){
                    initEditSomeSelect(videoStarrId,starrIds);
                }
            }
        }
    });
}
/**
 * 更改专辑后，歌曲可以选择的艺人
 * @param $album
 * @param videoStarrId
 */
function initMusicStarr($album,videoStarrId,starrIds){
    var albumId = $album.val();
    if(albumId == ''){
        return;
    }
    var url = '/vrs/musicalbum/one.jsn?musicAlbumId='+albumId;
    $.get(url,function(data,status){
        if(status == 'success'){
            var _status = data.success;
            if(_status){
                var optionList = new Array();
                optionList[0]='<option value=""></option>';
                $.each(data.data.starrings,function(i,item){
                    optionList[parseInt(i+1)]='<option value="'+item.starringId+'">'+item.name+'</option>';
                });
                var $newSelect = $('<select id="'+videoStarrId+'" required data-placeholder="请选择艺人"  multiple class="chosen" name="music.starringIds" style="width: 60%;">'+optionList.join()+'</select>');
                var $select =  $('#'+videoStarrId);
                $select.next().remove();
                $select.replaceWith($newSelect);
                $('.chosen').chosen();
                if(starrIds != ''){
                    initEditSomeSelect(videoStarrId,starrIds);
                }
            }
        }
    });
}


//edit页面数据初始化
function initEdit(){
    //tags类
    $('.tags').each(function(){
        $(this).tagsInput();
    });
    //chosen类

    //保存并添加下一个
    $('.save-next').click(function(e){
        e.preventDefault();
        var $thisSave = $(this);
        var $this = $('form[name="ajaxForm"]');
        //检查必填字段
        if (!$this.valid()) {
            return false;
        }
        swal({
            title: '确认此操作吗?',
            //text: 'You will not be able to recover this imaginary file!',
            type: 'warning',
            showCancelButton: true,
            //confirmButtonColor: '#DD6B55',
            confirmButtonText: '确定!',
            closeOnConfirm: false,
            cancelButtonText:'取消'
        },function(){
            beginForm()
            // 提交表单
            $this.ajaxSubmit(function(data){
                //console.log(data)
                if(data.success){
                    swal({
                        title: data.msg,
                        text: '点击返回',
                        type:'success'
                    },function(){
                        //window.location.href=document.referrer;//父窗口刷新
                        //location.reload();刷新
                        window.location.href = $thisSave.data('url');
                    });
                }else{
                    swal('操作失败', data.msg, 'error');
                    return false;
                }
                //alert(data.msg);
            });
        });
        // 为了防止普通浏览器进行表单提交和产生页面导航（防止页面刷新？）返回false
        return false;
    });
}
/**
 * 修改的时候初始化时间
 * @param id
 */
function initEditTime(id,time){
    if(time == ''){
        return;
    }
    var dateInput = $('#'+id);
    dateInput.val($.timeStampFormat(parseInt(time),FORMAT_DATETIME_DDMMYYHHMM));
    //console.log(dateInput.parent().parent().find('input.vrs-time'));
    dateInput.parent().parent().find('input.vrs-time').val($.timeStampFormat(parseInt(time),FORMAT_TIME_DDMMYYHHMM));
}
//修改的时候初始化艺人信息
function initEditStarrData(id,json){
    if(json == ''|| id == ''){
        return;
    }
    var data = $.evalJSON(json);
    var array = data.data;
    var $starrAdd = $('#'+id).find('div:last button')
    for(var i=0;i<array.length;i++){
        var starrId = array[i].starringId;
        var picArray = array[i].standardPic;
        $starrAdd.parent().prev().before(starrHtml1+starrHtml2);
        $starrAdd.parent().prev().prev().prev().html('')//新label内容制空
        //获取艺人选择select
        var $starrSelect  = $starrAdd.parent().prev().prev().find('div:first').find('select')
        $starrSelect.attr('id',starrId+'_starrid');
        initEditSelect(starrId+'_starrid',starrId)
        //初始化艺人下图片信息
        var $starrPicDiv = $starrAdd.parent().prev().prev();
        var newId = starrId+'_starrpicdiv'+getRandomString(4)
        $starrPicDiv.attr('id',newId)
        initEditPicArray(newId,picArray)
        $starrPicDiv.children(':eq(1)').remove()
        //
        initUploadImageCss();
        $('.chosen').chosen();
    }
    $('#'+id).find('label:eq(1)').remove().end().find('div:eq(0)').remove();
}
//初始化配图数组
function initEditPic(id,json){
    if(json == '' || id==''){
        return;
    }

    var data = $.evalJSON(json);
    var array = data.data;
    if(array == undefined){
        array = data.standardPic;
    }
    initEditPicArray(id,array)
    //console.log(array,$('#'+id).children(':eq(0)'));
    $('#'+id).children(':eq(0)').remove()
}
//初始化配图
function initEditPicArray(id,array){
    //console.log(array)
    var $addBut = $('#'+id).find('div:last button')
    //console.log('addbut',$addBut)
    for(var i=0;i<array.length;i++){
        var terminal = array[i].terminal;
        var url = array[i].url
        $addBut.parent().before(uploadHtml);
        //终端初始化赋值
        var $select  = $addBut.parent().prev().find('select[data-theme-name="terminal"]');
        var newId = terminal+'_terminal'+getRandomString(4)
        $select.attr('id',newId)
        initEditSelect(newId,terminal);
        //图片初始化赋值
        var $img = $addBut.parent().prev().find('img[data-theme-name="view-image"]');
        //console.log($img)
        $img.attr('src',url)

        initUploadImageCss();
        initUploadImageForm();
        $('.chosen').chosen();
    }
}
//修改时初始化radio
function initEditRadio(id,val){
    if(val == ''){
        return;
    }
    var $input = $('#'+id).find('label').find('span').find('i').find('input')
    $input.each(function(n){
        var value = $(this).val();
        if(value == val){
            $(this).parents('label').trigger('click');//parents('label').addClass('checked')
            $(this).trigger('click')

        }
    })
}

//修改时初始化填写标签类
function initEditInput(id,val){
    if(val == ''){
        return;
    }
    $('#'+id).val(val);
    $('#'+id).click();
    var html = '';
    var vals = val.split(',');
    for(var i=0;i<vals.length;i++){
        html = html + '<span class="tag"><span>'+vals[i]+'  </span><a href="#" title="Removing tag">x</a></span>';
    }
    //html = html + '<div id="tags_addTag"><input id="tags_tag" data-default="add a tag" value="" style="color: rgb(102, 102, 102); width: 68.1667px;">'+
    '</div><div class="tags_clear"></div>'
    var $div = $('#'+id+'_tagsinput').find('div:first');
    $div.prevAll().remove();
    $div.before(html);
    $div.prevAll().find('a').each(function(n){
        //console.log($(this))
        removeA($(this))
        //$(this).triggerHandler('click')
    })
}
//重新加载删除方法
function removeA($a){
    $a.click(function(e){
        e.preventDefault();
        //多选select时的操作
        var $li = $(this).parents('ul.chosen-choices').next().find('ul').find('li');
        //console.log($li.html())
        if($li.length>0){
            var value = $(this).attr('data-option-array-index')
            $li.each(function(n){
                var liValue = $(this).attr('data-option-array-index')
                if(liValue == value){
                    $(this).removeClass('result-selected').addClass('active-result')
                }
            })
        }
        $a.parent().remove();
    })
}


//修改时初始化多选select数据
function initEditSomeSelect(id,val){
    if(val == '-1'){
        return;
    }
    var text = '';
    var choiceHtml = '';
    $('#'+id).find('option').each(function(n){
        var value = $(this).val();
        var index = val.indexOf(value)
        console.log(index)
        if(index>-1 && value != ''){
            console.log(val,value)
            text = $(this).text();
            $(this).prop('selected','selected')
            choiceHtml = choiceHtml + '<li class="search-choice"><span>'+text+'</span><a class="search-choice-close" data-option-array-index="'+value+'"></a></li>'
        }
    })
    //对第三方组件做处理
    var $choice = $('#'+id+'_chosen').find('ul').find('li:last');
    $choice.prevAll().remove();
    $choice.before(choiceHtml);
    $('#'+id+'_chosen').find('ul.chosen-choices').find('li').find('a').each(function(n){
        removeA($(this))
    })
    $('.chosen').chosen();

}
//修改时初始化select数据
function initEditSelect(id,val){
    if(val == ''|| id == ''){
        return;
    }
    var text = '';
    var index = 0;
    $('#'+id).find('option').each(function(n){
        if($(this).val()==val){
            text = $(this).text();
            index= n;
            $(this).prop('selected','selected')
        }
    })
    //对第三方组件做处理
    $('#'+id+'_chosen').find('a').find('span').text(text);
    $('#'+id+'_chosen').find('div').find('ul').find('li[data-option-array-index="'+index+'"]').addClass('result-selected')
}
//准备时间组件
function initClock(){
    //改变日期
    $('.vrs-date').change(function(){
        $(this).parent().next().children('div').find('.vrs-time').val('');
    })
    //改变时间
    $('.vrs-time').change(function(){
        var $date = $(this).parent().parent().prev().find('.vrs-date')
        var time = $date.val();
        if(time == ''){
            var msg = '请先选择日期';
            var type = 'error';
            var $layout = 'topRight';
            notyRestart(msg,type,$layout);
            $(this).val('')
            return;
        }
        //console.log(time)
        time = time.substring(0,10);
        //console.log(time)
        $date.val(time+" "+$(this).val());
        //console.log($date.val());
    })
}

//提交前获取艺人json数据
function getStarrJson(){
    var starrList = new Array();//艺人集合
    var starrIds='';//艺人id集合
    $('div[data-theme-name="starr-div"]').find('div[data-theme-name="starr-sub-div"]').each(function(n){
        var $starrSelect = $(this).find('div:eq(0)').find('select');
        var starrId = $starrSelect.val();//艺人id
        var starrName = $starrSelect.find('option[value='+starrId+']').text();//艺人姓名
        //if(starrName.indexOf("'")>1){
        //    starrName = starrName.replace(/'/g, "\\'");
        //    console.log('starrName',starrName);
        //}
        //console.log(starrId,starrName)
        var starrPicList = new Array()//配图集合
        var starrPicCount = 0;//配图计数器
        $(this).find('div[data-theme-name="upload-image-div"]').each(function(){
            var terminal = $(this).find('select').val()//图片终端
            var url = $(this).find('img[data-theme-name="view-image"]').attr('src')//图片地址
            var map = putPicJson(terminal ,url,starrPicList,starrPicCount)
            starrPicList = map.array;
            starrPicCount = map.count;
            //console.log(1,terminal,url)
        })

        var starrJson = {starringId:starrId,name:starrName,standardPic:starrPicList}
        starrList[n] = starrJson;
        //收集艺人id
        starrIds = starrIds + "," + starrId;
    })
    var data = {data:starrList};
    data = $.toJSON(data)
    //console.log(data)
    $('#starringInfo').val(data)
    //艺人id赋值
    $('#starringIds').val(starrIds.substring(1));

}

//提交前获取封面json数据
function getPicJson(){
    var picArray = new Array();
    var picCount = 0;
    $('div[data-theme-name="upload-image"]').find('div[data-theme-name="upload-image-div"]').each(function(){
        var terminal = $(this).find('select').val()//图片终端
        var url = $(this).find('img[data-theme-name="view-image"]').attr('src')//图片地址
        var map = putPicJson(terminal ,url,picArray,picCount)
        picArray = map.array;
        picCount = map.count;
    })
    var data = {data:picArray};
    data = $.toJSON(data)
    $('#standardPic').val(data)
    return data;
}
//将图片信息储存成json
function putPicJson(terminal ,url,picList,picCount){
    var size = url.substring(url.lastIndexOf("_")+1,url.lastIndexOf("."));
    var map = {terminal:terminal,size:size,url:url};

    var terminalFlag;
    var index=-1;
    $.each(picList,function(n,value){
        $.each(value,function(name,value){
            if(name == "terminal"){
                terminalFlag = value == terminal;
                if(terminalFlag){
                    index = n;
                }
            }
            if(name == "url"){
                terminalFlag = value == url;
                if(terminalFlag){
                    index = n;
                }
            }
        })
    })
    if(index>-1){
        picList[index] = map;
    }else{
        picList[picCount] = map;
        picCount++;
    }

    return {array:picList,count:picCount};//picList;

}


var uploadHtml = $('.form-group').find('div[data-theme-name="upload-image-div"]:first').clone(true).prop('outerHTML');
//上传图片组件
function initUploadImage(){
    //准备组件
    var $addBut = $('button[data-theme-name="add-upload-image"]');//添加按钮
    var $removeBut = $('button[data-theme-name="remove-upload-image"]');//删除按钮
    //初始化组件样式
    initUploadImageCss();
    //初始化删除事件
    initUploadImageRemove($removeBut);
    //初始化上传图片事件
    initUploadImageForm();
    //初始化添加按钮事件   data-theme-name="upload-image-div"
    initUploadImageAdd($addBut)
}
function initUploadImageAdd($addBut){

    $addBut.click(function(){
        //console.log($addBut,uploadHtml);
        //$(this).parent().prev().clone(true).insertAfter($(this).parent().prev());
        $(this).parent().before(uploadHtml);
        var $removeBut = $(this).parent().prev().find('button[data-theme-name="remove-upload-image"]');
        var $openModal = $(this).parent().prev().find('[data-toggle="modal"]');
        if($openModal.length>0){
            initOpenModal($openModal);
        }
        initUploadImageCss();
        initUploadImageRemove($removeBut);
        initUploadImageForm();
        $('.chosen').chosen();
    });
}

//上传图片的change事件
var upload_image_url  =  "http://user.zhengzai.tv/api/upload/image/";//"/vrs/api/uploadimage/";//
function initUploadImageForm(){
    $('label[data-theme-name="upload-image-label"]').find('input[type="file"]').change(function(){

        var html = '<form method="post" enctype="multipart/form-data"></form>';
        var $form = $(html);
        var root = $(this).siblings('input[name="root"]').val();
        var $viewImg = $(this).siblings('img[data-theme-name="view-image"]')

        var $waitImg = $(this).siblings('img[data-theme-name="wait-image"]')
        $form.attr('action',upload_image_url+root);//+'.jsn');///'+root);//+".jsn");
        $form.append($(this).clone(true));
        $waitImg.show();
        //console.log($form.attr('action'),$form.children());
        $form.ajaxSubmit(function(data){
            var status = data.status;
            if(status == 1){

                $viewImg.attr('src',data.data);
                $waitImg.hide();
            }else{
                swal({
                    title: data.message,
                    text: '点击返回',
                    type:'success'
                });
                $waitImg.hide();
            }
        });
    });
}

//删除事件
function initUploadImageRemove($removeBut){
    $removeBut.click(function(){
        var $removeDiv = $(this).parent().parent().siblings('div[data-theme-name="upload-image-div"]');
        if($removeDiv.length>0){
            $(this).parent().parent().remove();
        }else{
            var msg = '最后一个不能删除';
            var type = 'error';
            var $layout = 'topRight';
            notyRestart(msg,type,$layout);
        }
    });
}

//准备上传图片组件css
function initUploadImageCss(){
    var $removeBut = $('button[data-theme-name="remove-upload-image"]');//删除按钮
    var $inputFile = $('label[data-theme-name="upload-image-label"]').find('input[type=file]');//提交file组件
    var $addBut = $('button[data-theme-name="add-upload-image"]');//添加按钮
    var $img = $('label[data-theme-name="upload-image-label"]').find('img[data-theme-name="view-image"]');//呈现图片
    var $waitImg = $('label[data-theme-name="upload-image-label"]').find('img[data-theme-name="wait-image"]');//呈现图片
    $waitImg.css({"z-index":"inherit","position":"relative","margin-left":"-144px","display":"none"});
    $removeBut.css({"width":"100px","height":"35px"}).addClass('mt10');
    var w = $img.width();
    var h = $img.height();
    $addBut.css({"width":"40px","height":h});
    $inputFile.css({"width":w,"height":h,"margin-top":"-82px","opacity":"0"})
}


//艺人组件
var starrHtml1 = $('div[data-theme-name="starr-div"]').find('label:first').clone(true).prop('outerHTML');
var starrHtml2 = $('div[data-theme-name="starr-div"]').find('div.col-sm-10:first').clone(true).prop('outerHTML');
function initStarr(){
    var $removeBut = $('button[data-theme-name="remove-upload-image"]');//删除按钮
    var $removeStarr = $('button[data-theme-name="remove-starr"]');//删除艺人按钮
    //准备css样式
    initUploadImageCss();
    initStarrRemove($removeStarr);
    var $addStarr = $('button[data-theme-name="add-starr"]');
    //console.log($addStarr.prop('outerHTML'))
    $addStarr.click(function(){
        $(this).parent().prev().before(starrHtml1+starrHtml2);
        $(this).parent().prev().prev().prev().html('')//新label内容制空
        var $removeBut = $(this).parent().prev().prev().find('button[data-theme-name="remove-upload-image"]');//获取内部删除组件
        var $addBut = $(this).parent().prev().prev().find('button[data-theme-name="add-upload-image"]');//获取内部添加组件
        var $removeStarr =  $(this).parent().prev().prev().find('button[data-theme-name="remove-starr"]')//获取删除艺人组件
        initUploadImageCss();
        initUploadImageRemove($removeBut);
        initUploadImageForm();
        initStarrRemove($removeStarr);
        initUploadImageAdd($addBut);
        $('.chosen').chosen();
    })
}

//删除艺人
function initStarrRemove($removeStarr){
    $removeStarr.click(function(){
        var $removeObj = $(this).parent().parent().siblings('div[data-theme-name="starr-sub-div"]');
        //console.log($removeObj.length);
        if($removeObj.length>0){
            $(this).parent().parent().prev().remove();
            $(this).parent().parent().remove();
        }else{
            var msg = '最后一个不能删除';
            var type = 'error';
            var $layout = 'topRight';
            notyRestart(msg,type,$layout);
        }
    })
}

/**
 * 提交form前的操作
 */
function beginForm(){
    var $form = $('form[name="ajaxForm"]');
    var id = $form.attr("id");
    if(id == "articleForm"){
        var $text = $('#content');
        var $contentdiv = $('#contentSummernote');
        var content = $contentdiv.next().find('.note-editable').html();
        console.log(content);
        $text.text(content);
    }else{
        getPicJson()
        getStarrJson()
        //时间的格式化
        $('.vrs-date').each(function(){
            //console.log()
            var time = $(this).val()
            var str = $.stringToTimeStamp(time);
            //console.log(time,str)
            $(this).next('.vrs-date-submit').val(str);
        })
    }
}

//提交form
function submitForm(){
    //$('button[name=submit]').click(function(){
    var $form = $('form[name="ajaxForm"]');
    //初始化表单必填项的点击效果
    initFocusRequired($form);
    //$form.validate();
    var $submit = $form.find('button.submit');
    //判断是否可以提交
    $submit.click(function(){
        if(checkForm($form)){
            $form.submit();
        }else{
            return false;
        }
    });
    $form.submit(function(e) {
        e.preventDefault();

        var $this = $(this);
        if(!checkForm($this)){
            return;
        }


        swal({
            title: '确认此操作吗?',
            //text: 'You will not be able to recover this imaginary file!',
            type: 'warning',
            showCancelButton: true,
            //confirmButtonColor: '#DD6B55',
            confirmButtonText: '确定!',
            closeOnConfirm: false,
            cancelButtonText:'取消'
        },function(){
            beginForm()
            // 提交表单
            $this.ajaxSubmit(function(data){
                //console.log(data)
                if(data.status==1){
                    swal({
                        title: data.message,
                        text: '点击返回',
                        type:'success'
                    },function(){
                        //window.location.href=document.referrer;//父窗口刷新
                        //location.reload();刷新
                        //window.location.href = $this.data('url');
                        //var aid = getValue('aid');
                        //var $removeTag = $(window.parent.document).find('#'+aid).find('i.fa-close');
                        //console.log($removeTag);
                        //top.removeTag($removeTag);
                        var pfs=parent.frames;
                        for(var i=0;i<pfs.length;i++)
                        {
                            if(pfs[i]==window)
                            {
                                window.parent.findRemoveByIframe(i);
                            }
                        }
                    });
                }else{
                    swal('操作失败', data.message, 'error');
                    return false;
                }
                //alert(data.msg);
            });
        });
        // 为了防止普通浏览器进行表单提交和产生页面导航（防止页面刷新？）返回false
        return false;
    });
    //})



}
/**
 * 初始化表单必填项的点击效果
 */
function initFocusRequired($form){
    var $required = $form.find(':required');
    $required.each(function(){
        var $this = $(this);
        var tagName = this.tagName;//标签名
        var value = $this.val();//值
        var type = $this.attr('type');//type
        var top = $this.offset().top;
        var $label = $this.parents('.form-group').find('label');

        $this.click(function(){
            $(this).removeClass('required-error');
            $label.removeClass('required-font-red');
        });
        $this.parents('label').click(function(){
            $(this).removeClass('required-error');
            $label.removeClass('required-font-red');
        });
        $this.next().click(function(){
                console.log('div click');
            $(this).removeClass('required-error');$label.removeClass('required-font-red');
        });
        //$this.next().find('input').click(function(){
        //    console.log('div click');
        //    $(this).removeClass('required-error');$label.removeClass('required-font-red');
        //});
        $this.next().children().click(function(){$(this).removeClass('required-error');$label.removeClass('required-font-red');});
        $this.next().children().on('blur',function(){$(this).removeClass('required-error');$label.removeClass('required-font-red');});
        //$this.next().find('a').click(function(){$(this).removeClass('required-error');$label.removeClass('required-font-red');});
        //$this.next().find('ul').click(function(){$(this).removeClass('required-error');$label.removeClass('required-font-red');});

        if(type == 'radio'){
            var name = $this.attr('name');
            var $radio = $form.find('input[type="radio"][name="'+name+'"]');
            var checked = false;
            $radio.each(function(){
                var isCheck = $(this).prop('checked');
                console.log(isCheck);
                if(isCheck){
                    checked = true;

                }
            });
            console.log(checked);
            if(!checked){
                $label.removeClass('required-font-red');
            }
        }

    });
}

/**
 * 检查表单内容是否有空值
 * @param $form
 * @returns {boolean}
 */
function checkForm($form){
    var $required = $form.find(':required');
    var topList = new Array();
    var count = 0;
    $required.each(function(){

        var $this = $(this);
        var tagName = this.tagName;//标签名
        var value = $this.val();//值
        var type = $this.attr('type');//type
        var top = $this.offset().top;
        var $label = $this.parents('.form-group').find('label');

        if(type == 'radio'){
            var name = $this.attr('name');
            var $radio = $form.find('input[type="radio"][name="'+name+'"]');
            var checked = false;
            $radio.each(function(){
                var isCheck = $(this).prop('checked');
                if(isCheck){
                    checked = true;

                }
            });
            if(!checked){
                $label.addClass('required-font-red');
            }
        }

        if(value == ''|| value == null ){


            if(tagName == 'SELECT'){//选择按钮
                $this.next().addClass('required-error');
                $this.next().find('a').addClass('required-error');
                $this.next().find('ul').addClass('required-error');
            }else{
                if(type == 'file'){
                    $this.parent('label').addClass('required-error');
                }else{
                    //输入框
                    $this.addClass('required-error');
                }

                if($this.next().hasClass('tagsinput')){
                    $this.next().addClass('required-error');
                }
            }
            $label.addClass('required-font-red');
            topList[count] = top;
            count++;
        }

    });
    $('html, body').animate({scrollTop:(topList[0]-20)});
    if(topList.length>0){
        return false;
    }
    return true;
}
